package com.syni.mdd.yhd.common.all.dao.jpa.platformGood;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsBusinessComplain;
import com.syni.mdd.yhd.common.all.entity.platformGood.BmsPlatformGood;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

public interface BmsPlatformGoodDao extends BaseJPADao<BmsPlatformGood,Integer> {

    @Transactional//事务的注解
    @Modifying //增删改必须有这个注解
    @Query(value = "update bms_platform_good set inventory = inventory - ?2,version = version + 1 " +
            "where id = ?1 and version = ?3",nativeQuery = true)
    Integer updateInventoryNum(Integer id,Integer num,Integer updateNumVersion);

    @Transactional//事务的注解
    @Modifying //增删改必须有这个注解
    @Query(value = "update bms_platform_good set inventory = inventory + ?2,version = version + 1 " +
            "where id = ?1 and version = ?3",nativeQuery = true)
    Integer updateLoseGoodInventory(Integer id, Integer num, Integer version);

    List<BmsPlatformGood> findByIdIn(Set<Integer> platformIds);
}

